# -*- coding: utf-8 -*-

from time import gmtime
from random import randint
from json import loads
from urllib2 import urlopen
from urllib import quote_plus, unquote_plus
from re import sub, search

__author__ = 'Sergey Sobko, Timir Nureev'
__copyright__ = 'Copyright (c) 2010, DEKO PROFIT (The ProfitWare Project)'
__license__ = 'BSD'
__credits__ = ['Sergey Sobko', 'Timir Nureev']
__email__ = 'info@dekoprofit.ru'
__status__ = 'Development'
__version__ = '0.4alpha'

notemptylist = lambda ckeys: (type(ckeys).__name__ in ['list', 'tuple'] or False) and len(ckeys) > 0 
concat_keys = lambda ckeys, cquotes='', delim=',': notemptylist(ckeys) and '%(q)s%(a)s%(q)s' % {'q': cquotes, 'a': ('%(q)s%(d)s %(q)s' % {'q': cquotes, 'd': delim}).join(map(lambda x: type(x).__name__ == 'str' and x or str(x), ckeys))} or ''
cd2 = lambda i: i < 10 and '0' + str(i) or str(i)
checkstr = lambda s: type(s).__name__ == 'str' and s or str(s)

time = gmtime()
date = cd2(time[2]) + '.' + cd2(time[1]) + '.' + cd2(time[0])
pdcs_version = lambda: __version__
r_int = lambda x: randint(1, x)
read_url = lambda x: urlopen(x).read()
json_read = lambda x: loads(read_url(x))
urldec = lambda x: unquote_plus(x)
urlenc = lambda x: quote_plus(urldec(x))
ch, re_s = sub, search